package com.ruoyi.order.controller;

import cn.hutool.core.bean.BeanUtil;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.order.api.RemoteOrdService;
import com.ruoyi.order.api.RemoteUserService;
import com.ruoyi.order.domain.CheEvaluate;
import com.ruoyi.order.domain.CheOrder;
import com.ruoyi.order.domain.CheUser;
import com.ruoyi.order.service.ICheEvaluateService;
import com.ruoyi.util.Result;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.annotation.Id;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName CheEvaluateController
 * @Description TODO
 * @Author zq
 * @Date 2024年06月11日 21:24
 * @Version 1.0
 */
@RestController
@RequestMapping("/evaluate")
@CrossOrigin
public class CheEvaluateController {
    @Autowired
    private ICheEvaluateService evaluateService;
    @Autowired
    private RemoteUserService userService;
    @Autowired
    private RemoteOrdService ordService;
    @GetMapping("/info")
    public Result getEvaluate(Long id){
        Map map = new HashMap();
        map.put("id",id);
        Map<Object, Object> map1 = evaluateService.selectByShopId(map);
//        System.out.println(map1);
        return Result.success(map1);
    }

    @GetMapping("/list")
    public Result getEvaluateList(CheEvaluate cheEvaluate){
        List<CheEvaluate> list = evaluateService.getList(cheEvaluate);
        for (CheEvaluate evaluate : list){
            AjaxResult serviceInfo = userService.getInfo(evaluate.getUserId());
            LinkedHashMap data = (LinkedHashMap) serviceInfo.get("data");
            CheUser cheUser = BeanUtil.mapToBean(data, CheUser.class, true);
            evaluate.setUserName(cheUser.getRealName());
            AjaxResult info = ordService.getInfo(evaluate.getOrderIdw());
            LinkedHashMap data1 = (LinkedHashMap) info.get("data");
            CheOrder cheOrder = BeanUtil.mapToBean(data1, CheOrder.class, true);
            System.out.println(cheOrder.getNumber());
            evaluate.setOrderCode(cheOrder.getNumber());
        }
        return Result.success(list);
    }
    //根据id查询评价信息
    @GetMapping(value = "/{id}")
    public  Result getByIdInfo(@PathVariable("id") Long id){
        CheEvaluate cheEvaluates = evaluateService.selectById(id);
        return Result.success(cheEvaluates);
    }

//

}
